<?php
/**
 *  base.php 框架入口文件
 */
 
define('IN', true);
//框架路径
define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

error_reporting(E_ERROR | E_WARNING | E_PARSE);

//输出页面字符集
header('Content-type: text/html; charset='.CHARSET);
base::load_fun_class('global');
class base {
	
	/**
	 * 初始化应用程序
	 */
	public static function creat_app() {
		return self::load_sys_class('application');
	}
	/**
	 * 加载函数方法
	 * @param string $classname 类名
	 * @param string $path 扩展地址
	 */
	public static function load_fun_class($classname, $path = '') {
			return self::_load_fun($classname, $path, $initialize);
	}
	/**
	 * 加载系统类方法
	 * @param string $classname 类名
	 * @param string $path 扩展地址
	 * @param intger $initialize 是否初始化
	 */
	public static function load_sys_class($classname, $path = '', $initialize = 1) {
			return self::_load_class($classname, $path, $initialize);
	}
		/**
	 * 加载类文件函数
	 * @param string $classname 类名
	 * @param string $path 扩展地址
	 * @param intger $initialize 是否初始化
	 */
	private static function _load_class($classname, $path = '', $initialize = 1) {
		static $classes = array();
		if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'classes';

		$key = md5($path.$classname);
		if (isset($classes[$key])) {
			if (!empty($classes[$key])) {
				return $classes[$key];
			} else {
				return true;
			}
		}
		if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
			include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php';
			$name = $classname;
			
			if ($initialize) {
				$classes[$key] = new $name;
			} else {
				$classes[$key] = true;
			}
			return $classes[$key];
		} else {
			return false;
		}
	}
	private static function _load_fun($classname, $path = '') {
		if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions';
		if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.fun.php')) {
			include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.fun.php';
			return true;
		} else {
			return false;
		}
	}
}
?>